﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Documents;

namespace SDF.Pagination
{
    public class HarvestingContext
    {
        #region Constructor

        public HarvestingContext()
        {
            HarvestedElements = new List<DependencyObject>();
            CurrentPage = 1;
            SectionsPageCount = new Dictionary<Guid, int>();
        }

        #endregion

        #region Properties

        protected List<DependencyObject> HarvestedElements { get; private set; }

        public int CurrentPage { get; set; }

        public Guid CurrentSection { get; set; }

        public Dictionary<Guid, int> SectionsPageCount { get; private set; }

        #endregion

        #region Methods

        public void MarkAsFullyHarvested(DependencyObject element)
        {
            if (!HarvestedElements.Contains(element))
                HarvestedElements.Add(element);
        }

        public bool IsFullyHarvested(DependencyObject element)
        {
            return HarvestedElements.Contains(element);
        }

        public bool HasStartedHarvesting(DependencyObject element)
        {
            if (IsFullyHarvested(element))
                return true;

            var harvestable = element as IHarvestable;
            if (harvestable != null)
                return harvestable.IsPartiallyHarvested(this);

            return false;
        }

        #endregion
    }
}
